package com.bruce.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;


/**
 * @author cc
 * @date 2021/7/26 9:36
 * @Description
 */
@AllArgsConstructor
@NoArgsConstructor
public class PageUtils<T> {
    private  int pagesize; //每页大小
    private   int pageIndex; //当前页
    private   int pageCount ;//总页数
    private   int countAll ;//总记录条数
    private List<T> records;
    private List<Integer> num = new ArrayList<Integer>();

    public List<Integer> getNum() {
        return num;
    }

    public void setNum(List<Integer> num) {
        this.num = num;
    }

    public PageUtils(int pagesize, int pageIndex, int countAll) {
        this.pagesize = pagesize;
        this.pageIndex = pageIndex;

        this.pageCount = countAll % pagesize ==0?(countAll/pagesize):(countAll/pagesize+1);

        this.countAll = countAll;

        if (pageCount<2){
            num.add(1);
        }else {
            for (int i=0;i<pageCount;i++){
                num.add(i+1);
            }
        }

    }

    public int getPagesize() {
        return pagesize;
    }

    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int countAll) {
        this.pageCount = countAll % pagesize ==0?(countAll/pagesize):(pageCount/pagesize+1);
    }
    public void setPageCounts(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getCountAll() {
        return countAll;
    }

    public void setCountAll(int countAll) {
        this.countAll = countAll;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }
}
